; Initialization:
		org	0
		di
		im	1		; RST 38h mode
		xor	a		; LED off
		ld	i,a
		ld	d,80h		; D bit 7 on, rest off
		jp	testIFF2

; WARNING: There's very little room to add anything to the initialization or
; to the Morse routine before the interrupt handler of mode 1.

; This is the output routine. It keeps outputting the bits of D endlessly.
; The ON time is long or short depending on the bit value, while the OFF time
; is short between bits, and long to distinguish that a new repetition is
; about to start (it always starts with a long OFF).
Morse:		ld	e,8		; 8 bits counter
		ld	b,210		; Long space, used as separator
Morse2:		xor	a		; LED off
		ld	i,a
Morse3:		dec	bc
		ld	a,b
		or	c
		jr	nz,Morse3	; Delay
		ld	a,4		; LED on
		ld	i,a
		ld	b,70		; Short flash
		rlc	d
		jr	nc,Morse4	; If current bit is 0, keep it Short
		ld	b,210		; Long flash
Morse4:		dec	bc
		ld	a,b
		or	c
		jr	nz,Morse4	; Delay
		ld	b,70		; Space between flashes is short
		dec	e		; Next bit
		jr	nz,Morse2	; Loop unless all 8 bits displayed
		jr	Morse		; Loop forever (sets space to long)

		org	38h
		; INT ISR
		jp	po,Morse	; If IFF2 was zero, leave bit 5 as 0
		set	5,d		; Set bit 5 to signal that IFF2 was 1
		jr	Morse

testIFF2:	ei
		ld	a,r		; INT should happen after this; next
					; instruction should never execute
		set	4,d		; Should not be reached
		jr	Morse

; Result:
; Bits set: 7 only
; - Bit 7 set means it executed the initialization.
; - Bit 5 clear means IFF2 was clear.
; - Bit 4 clear means that the interrupt routine executed correctly.
; - Rest of bits are never set.
